import request from '@/utils/request';
import { HospitalResponseData, HospitalLevelAndRegionResponseData, HospitalInfoResponseData } from './type';

enum API {
	// 获取医院列表
	HOSPITAL_LIST = '/hosp/hospital',
	// 获取医院等级与地区
	HOSPITAL_LEVE_AND_REGION_LIST = '/cmn/dict/findByDictCode',
	// 根据名称获取医院信息
	HOSPITAL_INFO_BY_NAME = '/hosp/hospital/findByHosname',
}

// 获取医院列表
export const getHospitalList = (page: number, limit: number, hostype?: string, districtCode?: string) => {
	type T = {
		hostype?: string;
		districtCode?: string;
	};

	const data: T = {};

	if (hostype) {
		data.hostype = hostype;
	}

	if (districtCode) {
		data.districtCode = districtCode;
	}

	return request.get<any, HospitalResponseData>(`${API.HOSPITAL_LIST}/${page}/${limit}`, {
		params: data,
	});
};

// 获取医院等级与地区
export const getHospitalLeveAndRegionList = (dictCode: 'HosType' | 'Beijin') => {
	return request.get<any, HospitalLevelAndRegionResponseData>(`${API.HOSPITAL_LEVE_AND_REGION_LIST}/${dictCode}`);
};

// 根据名称获取医院信息
export const getHospitalInfoByName = (hosname: string) => {
	return request.get<any, HospitalInfoResponseData>(`${API.HOSPITAL_INFO_BY_NAME}/${hosname}`);
};
